package com.explorex.infra.puma.gateway.netty.common.enums;


import com.explorex.infra.puma.gateway.netty.common.ConstValue;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * Created by wuhaodong on 2018/4/28.
 * Business type for OldConnectorMessage
 */
public class BusinessType {

    public static final short PING = 0x000;

    public static final short AUTH = 0x0100; // 登录鉴权
    public static final short LOGOUT = 0x0200;// 登录相关
    public static final short COMMON = 0x0300; // 回调通用

    // business 定义范围  0x01~0x0F
    public static final short IM = 0x0001;
    public static final short PUSH = 0x0002;
    public static final short RENO_SERVICE = 0x0003;
    public static final short ROOM = 0x0004;
    public static final short IMPAAS_SERVICE = 0x000a;

    /**
     * 0x0000 ～ 0xff00 长连接系统预留
     * - 0x0000	ping  心跳包
     * - 0x0100	鉴权 请求包
     * - 0x0200	登出 请求包
     * 0x0001 ~ 0xff01	M 业务
     * 0x0002 ~ 0xff02	Push 业务
     * 0x0003 ~ 0xff03	Reno 业务编码
     * 0x0004 ~ 0xff04	直播房间业务编码
     */

    private static final Map<Short, String> desc = new HashMap<>();

    //  define the business type name here
    static {
        desc.put(PING, ConstValue.PING);
        desc.put(AUTH, ConstValue.AUTH);
        desc.put(IM, ConstValue.IM);
        desc.put(PUSH, ConstValue.PUSH);
        desc.put(RENO_SERVICE, ConstValue.RENO);
        desc.put(ROOM, ConstValue.ROOM);
        desc.put(IMPAAS_SERVICE, ConstValue.IMPAAS);
    }

    public static String valueOf(short value) {
        return Optional.ofNullable(desc.get(value)).orElse("undefined");
    }

}
